//获取当前时间
var myDate = new Date();
var myYear = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
var myMonth = myDate.getMonth()+1; //获取当前月份(0-11,0代表1月)
var myToday = myDate.getDate(); //获取当前日(1-31)
var myDay = myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
var myHour = myDate.getHours(); //获取当前小时数(0-23)
var myMinute = myDate.getMinutes(); //获取当前分钟数(0-59)
var mySecond = myDate.getSeconds(); //获取当前秒数(0-59)
var newTime = myYear+'-'+myMonth+'-'+myToday+' '+myHour+':'+myMinute+':'+mySecond;
$('input[name=startDate]').val(newTime);

//计算结束时间
var getTimeEnd;
function getTimeEnd(year,day){

    var myDate = new Date();
    var myYear = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
    myYear = myYear + year;

    var myMonth = myDate.getMonth()+1; //获取当前月份(0-11,0代表1月)
    var myToday = myDate.getDate(); //获取当前日(1-31)

    var myToday = myToday + day;
    if(myToday>30){
        myToday = myToday - 30;
        myMonth = myMonth + 1;
        if(myMonth > 12){
            myMonth = 1;
            myYear = myYear + 1;
        }
    }

    var myHour = myDate.getHours(); //获取当前小时数(0-23)
    var myMinute = myDate.getMinutes(); //获取当前分钟数(0-59)
    var mySecond = myDate.getSeconds(); //获取当前秒数(0-59)
    getTimeEnd = myYear+'-'+myMonth+'-'+myToday+' '+myHour+':'+myMinute+':'+mySecond;
};
var $,layer,form,table,laydate,upload;
layui.use(['jquery','layer','form','table','laydate','upload'],function(){
    $ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate,upload = layui.upload;

    form.on('submit(sub)',function(data){
        var data = data.field;
        var days = parseInt(data.days);
        console.log(days);
        if(days < 99){
            console.log(1);
            getTimeEnd(0,days);
            data.endDate = getTimeEnd;
        }else if(days == 99){
            console.log(2);
            getTimeEnd(days,0);
            data.endDate = getTimeEnd;
            data.days = 36135;
        }else{
            layer.msg('错误，请稍后再试');
            return;
        }
        var userId = data.userId;
        //添加封禁信息
        $.ajax({
            url: '/user/shutDown'
            ,data: data
            ,dataType: 'json'
            ,success:function(data){
                //修改用户状态
                $.ajax({
                    url: '/user/editStatus'
                    ,data: {'userId': userId}
                    ,dataType: 'json'
                    ,success:function(data){
                        parent.getUsers(userId);
                        var layer = parent.layer;
                        layer.close(layer.index);
                        layer.msg('已封禁');
                    }
                });
            }
        });
    });
    //取消
    cancel = function cancel(){
        var layer = parent.layer;
        layer.close(layer.index);
    }
});

var userId = parent.$('#userId').val();
$('input[name=userId]').val(userId);
var account = parent.$('#account').val();
$('input[name=account]').val(account);
